﻿using System;
using System.Collections.Generic;
using Volo.Abp.EventBus;

namespace Mozhi.Abp.OperationLog
{
    [EventName("mozhi.smarterp.operationlog")]
    public class OperationLogRecordEvent
    {
        public Guid Id {   set; get; }

        public Guid? TenantId { get; set; }

        public Guid? OperatorId {   set; get; }

        public string OperatorName {   set; get; }

        public OperationType Type {   set; get; }

        /// <summary>
        /// 模块代码
        /// </summary>
        public string ModuleCode {   set; get; }

        /// <summary>
        /// 模块名称
        /// </summary>
        public string ModuleName {   set; get; }


        public Guid ObjectId {   set; get; }

        public string ObjectName {   set; get; }

        public string Comment {   set; get; }

        public List<OperationLogRecordEventItem> Items {   set; get; }

        public OperationLogRecordEvent(Guid id, Guid? tenantId, Guid? operatorId, string operatorName, OperationType type, string moduleCode, string moduleName, Guid objectId, string objectName, string comment)
        {
            Id = id;
            TenantId = tenantId;
            OperatorId = operatorId;
            OperatorName = operatorName;
            Type = type;
            ModuleCode = moduleCode;
            ModuleName = moduleName;
            ObjectId = objectId;
            ObjectName = objectName;
            Comment = comment;
            Items = new List<OperationLogRecordEventItem>();
        }

        public void ChangeItems(List<OperationLogRecordEventItem> items)
        {
            Items.AddRange(items);
        }

    }

    public class OperationLogRecordEventItem
    {
        public Guid? TenantId { get; set; }

        public Guid Id {   set; get; }

        public Guid OperationLogId {   set; get; }

        public string FieldName {   set; get; }

        public string FieldCaption {   set; get; }

        public string FieldOldValue {   set; get; }

        public string FieldOldCaptionValue {   set; get; }

        public string FieldNewValue {   set; get; }

        public string FieldNewCaptionValue {   set; get; }

        public string Comment {   set; get; }


        public OperationLogRecordEventItem(Guid id, Guid? tenantId, Guid operationLogId, string fieldName, string fieldCaption,
            object fieldOldValue, string fieldOldCaptionValue, object fieldNewValue, string fieldNewCaptionValue, string comment)
        {
            Id = id;
            TenantId = tenantId;
            OperationLogId = operationLogId;
            FieldName = fieldName;
            FieldCaption = fieldCaption;
            FieldOldValue = fieldOldValue?.ToString();
            FieldOldCaptionValue = fieldOldCaptionValue;
            FieldNewValue = fieldNewValue?.ToString();
            FieldNewCaptionValue = fieldNewCaptionValue;
            Comment = comment;
        }
    }
}
